package com.chapter.sample.service.impl;

import com.chapter.sample.dao.UserDao;
import com.chapter.sample.mapper.UserMapper;
import com.chapter.sample.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.servlet.ServletConfig;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class UserServiceImpl implements UserService, InitializingBean,
        ApplicationContextAware, BeanFactoryAware, BeanNameAware {


    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    private UserMapper userMapper;

    /*//注入list集合
    private List<String> stringList;

    private List<UserDao> userDaoList;

    private Set<String> strSet;

    private Set<UserDao> userDaoSet;

    private Map<String, String> strMap;

    public void setStrMap(Map<String, String> strMap) {
        this.strMap = strMap;
    }

    public void setUserDaoMap(Map<String, UserDao> userDaoMap) {
        this.userDaoMap = userDaoMap;
    }

    private Map<String, UserDao> userDaoMap;

    public void setStrSet(Set<String> strSet) {
        this.strSet = strSet;
    }

    public void setUserDaoSet(Set<UserDao> userDaoSet) {
        this.userDaoSet = userDaoSet;
    }

    public void setUserDaoList(List<UserDao> userDaoList) {
        this.userDaoList = userDaoList;
    }

    public void setStringList(List<String> stringList) {
        this.stringList = stringList;
    }*/

    @Override
    public void show() {
//        System.out.println(stringList);
//        System.out.println(userDaoList);
//        System.out.println(strSet);
//        System.out.println(userDaoSet);
//        System.out.println(strMap);
//        System.out.println(userDaoMap);
        //System.out.println(userDao);

        userMapper.findAll().forEach(user -> System.out.println(user));
    }

    private String userName;

    public void setUserName(String userName) {
        this.userName = userName;
    }

    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        System.out.println("BeanFactory去调用该方法，从容器中获得userDao设置到此处" + userDao);
        this.userDao = userDao;
    }

    public UserServiceImpl() {
        System.out.println("userService创建");
    }

    //    private void init(){
//        System.out.println("初始化方法init");
//    }
//
//    private void destroy(){
//        System.out.println("销毁方法destroy");
//    }
//    public UserServiceImpl() {
//        System.out.println("UserServiceImpl实例化");
//    }
//
//    //BeanFactory去调用该方法，从容器中获得userDao设置到此处
//    public void setUserDao(UserDao userDao) {
//        System.out.println("BeanFactory去调用该方法，从容器中获得userDao设置到此处" + userDao);
//    }
//
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet执行");
    }

//    @Override
//    public void setServletConfig(ServletConfig servletConfig) {
//        System.out.println(servletConfig);
//    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println(applicationContext);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println(beanFactory);
    }

    @Override
    public void setBeanName(String s) {
        System.out.println(s);
    }
}
